package com.opencloud.iot.provider.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.opencloud.common.model.PageParams;
import com.opencloud.common.model.ResultBody;
import com.opencloud.iot.client.model.entity.IotConfigs;
import com.opencloud.iot.client.model.entity.IotTask;
import com.opencloud.iot.client.model.entity.IotTaskRun;
import com.opencloud.iot.provider.service.IotConfigsService;
import com.opencloud.iot.provider.service.IotTaskRunService;
import com.opencloud.iot.provider.service.IotTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 物联设备 任务列表
 * @author yeyong
 */
@RestController
@Api(value = "物联网设备", tags = "物联网设备 任务列表")
public class IotTaskController {
    @Autowired
    private IotTaskService iotTaskService;

    @Autowired
    private IotTaskRunService iotTaskRunService;

    /**
     * 获取任务配置列表
     * @param map
     * @return
     */
    @ApiOperation(value = "获取任务配置列表", notes = "获取任务配置列表")
    @GetMapping("/task/list")
    public ResultBody<IPage<IotTask>> getTaskListPage(@RequestParam(required = false) Map map){
        return ResultBody.ok().data(iotTaskService.findListPage(new PageParams(map)));
    }

    /**
     * 获取任务执行列表
     * @param map
     * @return
     */
    @ApiOperation(value = "获取任务执行列表", notes = "获取任务执行列表")
    @GetMapping("/taskrun/list")
    public ResultBody<IPage<IotTaskRun>> getTaskRunListPage(@RequestParam(required = false) Map map){
        return ResultBody.ok().data(iotTaskRunService.findListPage(new PageParams(map)));
    }

    /**
     * 新增任务配置
     * @param entiy
     * @return
     */
    @ApiOperation(value = "新增任务配置", notes = "新增任务配置")
    @GetMapping("/task/add")
    public ResultBody<Integer> addTask(@RequestParam(required = false) IotTask entiy){
        return ResultBody.ok().data(iotTaskService.AddTask(entiy));
    }

    /**
     * 编辑任务配置
     * @param entiy
     * @return
     */
    @ApiOperation(value = "编辑任务配置", notes = "编辑任务配置")
    @GetMapping("/task/update")
    public ResultBody<Integer> updateTask(@RequestParam(required = false) IotTask entiy){
        return ResultBody.ok().data(iotTaskService.UpdateTask(entiy));
    }
}
